'use strict';
app.controller('modulesAdvertisementAddCtrl',['$scope','$state','$stateParams','modulesAdvertisementAddService','utilService','toaster',function($scope,$state,$stateParams,modulesAdvertisementAddService,utilService,toaster){
    $scope.modulesId=$stateParams.modulesId;
    $scope.imgQueue=[];

    $scope.getList=function(){
        modulesAdvertisementAddService.getList($scope).then(function (result) {
            switch (result.status) {
                case 200:
                    $scope.advertiseTypes = result.data;
                    break;
                case 633:
                    toaster.pop('waiting', "提示", result.message);
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break
            }
        });
    }

    $scope.getList();

    //添加模块广告
    $scope.modulesAdvertisementAddService=modulesAdvertisementAddService;

    $scope.abledState=true;

    $scope.addModulesAdvertise=function(){
        if($scope.imgQueue.length>0){
            $scope.modulesAdvertisementAddService.modulesAdvertiseAddVO.imgUrl=$scope.imgQueue[0].fileName;
        }

        if(!$scope.abledState){
            return;
        }
        $scope.abledState=false;

        modulesAdvertisementAddService.addModulesAdvertise($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.go('app.modulesAdvertisement',{modulesId:$scope.modulesId});
                    $scope.modulesAdvertisementAddService.modulesAdvertiseAddVO={sort:0};
                    break;
                case 658:
                    toaster.pop('waiting', "操作失败", result.message);
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }

            $scope.abledState=true;
        })

    }



}])